﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Customer_Profile.eCard.DBDao;
using KVB.Common;
using System.IO;
using Customer_Profile.Admin;

namespace Customer_Profile.eCard.CardAccount
{
    public partial class CardBalance : System.Web.UI.Page
    {
        string strUserName = "";
        string strUserID = "";
        string strEntity = "";
        public string card_balance = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Comm.CheckSession(this.Page, "/login.aspx", "usermodel");
            if (Session["usermodel"] != null)
            {
                strUserID = ((UserInfoEntity)Session["usermodel"]).UserLoginId;
                strUserName = ((UserInfoEntity)Session["usermodel"]).UserName;
                strEntity = ((UserInfoEntity)Session["usermodel"]).UserOffice;
            }
            else
            {
                Log.WriteDefaultLog("main_01 Page_Load", "Session is null");
                return;
            }

            string strURL = HttpContext.Current.Request.Url.AbsolutePath;
            bool bok = Comm.ifhasright(strUserID, strURL);
            if (!bok)
            {
                Response.Write("你无权访问此页面");
                Response.End();
            }

            bindTransfer();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            
        }

        private void bindTransfer()
        {
            try
            {
                string card_no = txtCardNo.Text.Trim();
                if (card_no.Equals(""))
                {
                    lblWaring.Text = "卡片号码不能为空！";
                }
                else
                {
                    string status = "";
                    string message = "";
                    //1,检查卡号是否存在，
                    //2,检查卡号是否已经通过审查。
                    //3,卡片是否被锁定。
                    DataSet ds = DealDao.getCardBalance(card_no, out status, out message);
                    if (status.Equals("Y"))
                    {
                        gridCflows1.DataSource = ds.Tables[0].DefaultView;
                        gridCflows1.DataBind();

                        txtCardBalance.Text = ds.Tables[1].Rows[0]["card_balance"].ToString();
                        lblCpartyName.Text = ds.Tables[1].Rows[0]["cparty_name"].ToString();
                        lblIdno.Text = ds.Tables[1].Rows[0]["id_no"].ToString();
                        lblPhone.Text = ds.Tables[1].Rows[0]["phone"].ToString();
                        card_balance = ds.Tables[1].Rows[0]["card_balance"].ToString();
                        lblWaring.Text =message;
                        lblDesignee.Text = ds.Tables[1].Rows[0]["designee"].ToString();
                    }
                    else
                    {
                        lblWaring.Text = message;
                        txtCardBalance.Text = "";
                        lblCpartyName.Text = "";
                        lblIdno.Text = "";
                        lblPhone.Text = "";
                        lblDesignee.Text = "";
                        gridCflows1.DataSource = null;
                        gridCflows1.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                txtCardBalance.Text = "";
                lblCpartyName.Text = "";
                lblIdno.Text = "";
                Response.Write(ex.ToString());                
            }
        }
    }
}